package com.example.intenttrial;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class VimeoVideoActivity extends Activity {//implements OnCompletionListener {
	
	private WebView mWebView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.screen_vimeo_video);
		
		mWebView = (WebView)findViewById(R.id.wv_vimeo);
		
	}

	@Override
	protected void onResume() {
		super.onResume();

		play();
		
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		
		mWebView.clearCache(true);
		mWebView.clearView();
		
	}
	
	private void play() {
		
		mWebView.setWebViewClient(new MyWebViewClient());
		mWebView.setWebChromeClient(new WebChromeClient());
		
		mWebView.getSettings().setPluginsEnabled(true);
		mWebView.getSettings().setPluginState(PluginState.ON);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		
//		String data = "<iframe src=\"http://www.youtube.com/embed/Kpmy08g9Pao\" frameborder=\"0\" width=\"560\" height=\"315\" allowfullscreen></iframe>";
//		String data = "<iframe src=\"http://player.vimeo.com/video/62409118\" width=\"400\" height=\"300\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
		String data = "<html><body><iframe src=\"http://player.vimeo.com/video/62409118\" width=\"500\" height=\"300\" frameborder=\"3\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></body></html>";
		
		mWebView.loadData(data, "text/html", "UTF-8");
		
	}
	
	private class MyWebViewClient extends WebViewClient {
	    @Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {

	    	return false;
	    }

		@Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			System.out.println("--------onReceivedError " + description);
			super.onReceivedError(view, errorCode, description, failingUrl);
		}
		
		@Override
		public void onLoadResource(WebView view, String url) {
			System.out.println("-----------onLoadResource " + url);
			super.onLoadResource(view, url);
		}
	}
	
}
